﻿using EA.BA;
using EA.Common;
using EA.DTO;
using EAWebAdmin.template;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace EAAdmin
{
    public partial class ViewCustomer : WebPage
    {
        override
        protected void Load(object sender, EventArgs e)
        {
            int page = Request["page"]==null?1:Convert.ToInt32(Request["page"]);
            CustomerBA customerBA = new CustomerBA();
            List<CustomerTO> listCustomer = customerBA.GetAllCustomer(page);
            Attributes.Add("listCustomer", listCustomer);
            Attributes.Add("totalCustomer", customerBA.GetTotalAllCustomer());
            Attributes.Add("page",page);
        }

        public void Delete(HttpRequest Request, HttpResponse Response)
        {
            if (Request["id"] != null && !"".Equals(Request["id"]) && StringUtil.IsPositiveNumber(Request["id"]))
            {
                CustomerBA customerBA = new CustomerBA();
                int ID = Convert.ToInt32(Request["id"]);
                CustomerTO customerTO = customerBA.GetCustomerByID(ID);
                if (customerTO == null)
                {
                    Attributes.Add("err", "Customer is invalid");
                    this.isLoad = true;
                    return;
                }
                Boolean stt = customerBA.DeleteCustomer(ID);
                if (stt)
                {
                    Attributes.Add("success", "Delete successfully");
                    this.isLoad = true;
                }
                else
                {
                    Attributes.Add("err", "Delete faulty");
                    this.isLoad = true;
                    return;
                }
            }
                
        }
    }
}